package com.ishare.admin.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @description: 文档api
 * @author: DENGMINGWEN
 * @time: 2020/12/30 9:58
 */
@Configuration
@EnableKnife4j
@EnableSwagger2WebMvc
@ConditionalOnExpression("${knife4j.enable}")
public class SwaggerConfiguration {


    @Bean(value = "defaultApi")
    public Docket defaultApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("运营平台接口")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("互联网+运营平台API")
                .description("互联网+运营平台 后端 RESTful APIs")
                .termsOfServiceUrl("http://www.dengmingwen.com.cn")
                .contact(new Contact("dmw", "http://www.dengmingwen.com.cn", "awun0340@163.com"))
                .version("1.0")
                .build();
    }

}
